package hu.vpszd.beans

import hu.vpszd.entities.Role
import hu.vpszd.entities.User
import hu.vpszd.entities.transaction.LoanApplication
import hu.vpszd.service.UserDetailsService
import hu.vpszd.services.LoanApplicationService

import javax.faces.bean.SessionScoped

import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
@SessionScoped
class WorkbenchBean {
	private static final Logger logger = Logger.getLogger(WorkbenchBean.class);
	@Autowired
	private LoanApplicationService loanApplicationService

	LoanApplication selected
	List<LoanApplication> loanApplications = []

	@Autowired
	private UserDetailsService userService;

	List<LoanApplication> getLoanApplications() {
		loanApplications = []
		User user = userService.currentUser;
		if (user.roles.contains(Role.REFERENS)) {
			logger.debug('referens ág');
			loanApplications = loanApplicationService.findByStatus(0) + loanApplicationService.findByStatus(1)
		}
		else if (user.roles.contains(Role.BIRALO)) {
			//			loanApplications = loanApplicationService.findByStatus(2) + loanApplicationService.findByStatus(3)
			loanApplications = loanApplicationService.findByStatus(2) + loanApplicationService.findByStatus(3)
			logger.debug('biralo ág');
		}
		else{
			println("Eltérő USER")
		}
		return loanApplications
	}
}
